package com.itrui.encrypted_transmission.Thread;

import com.itrui.encrypted_transmission.CodeUtils;
import com.itrui.encrypted_transmission.MyFile;

import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.util.ArrayList;

public class TClient {
    public static void main(String[] args) throws IOException, InterruptedException {
       /* System.out.println("正在准备发送文件...");
        ArrayList<MyFile> files = toMyFiles("D:\\RuiProject\\FileTest");

        int[][3] = {{},}

        for (int i = 0; i < files.size();i++){
            Clients clients = new Clients(files.get(i));
            clients.clientRun();
        }
        System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
        System.out.println("全部发送成功！");*/



    }

    /**
     * 将文件列表封装成自定义文件对象
     *
     * @param path
     * @return
     */
    public static ArrayList<MyFile> toMyFiles(String path) {
        File dic = new File(path);
        String[] filesName = dic.list();

        ArrayList<MyFile> files = new ArrayList<>();
        for (int i = 0; i < filesName.length; i++) {
            File file = new File(path + "\\" + filesName[i]);
            if (file.isFile() && file.exists()) {
                MyFile myFile = new MyFile();
                myFile.setSize(file.length());
                myFile.setName(filesName[i]);
                String pic = CodeUtils.encodeFile(path + "\\" + filesName[i]);
                myFile.setFile(pic);
                files.add(myFile);
            }
        }
        return files;
    }
}
